#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;


class Solution {
public:
    int maximumUniqueSubarray(vector<int>& nums) {
	unsigned int temp = 0;
	unsigned int res = 0;
	set<int> numset;
	int begin = 0;
	int end = 0;
	while(end < nums.size())
	{
		if(numset.find(nums[end]) != numset.end())
		{
			temp -= nums[begin];
			numset.erase(nums[begin]);
			++begin;
		}
		else 
		{
			temp += nums[end];
			res = max(res,temp);
			if(end == nums.size())
				break;
			numset.insert(nums[end]);
			++end;
		}
	}
	return res;
    }
};


int main()
{
	vector<int> a = {4,2,4,5,6};
	Solution s;
	cout<<s.maximumUniqueSubarray(a);
}
